package com.rybbaby.tss.${baseInfo.modulesName}.${baseInfo.entityName?uncapFirst}.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
<#if table.foreignKeys?size gt 0>
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.FetchType;
import com.rybbaby.tss.core.utils.StringUtils;
</#if>
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
<#list table.columns as po>
	<#if po.isPrimaryKey&&!po.isAutoIncrement>
import org.hibernate.annotations.GenericGenerator;
	</#if>
	<#if  po.isVersionIdentifying?? && po.isVersionIdentifying?string("yes","no")=="yes" >
import javax.persistence.Version;
	 </#if>
</#list>
<#assign tempImprEntity="">
<#list table.foreignKeys as refTable>
<#if (tempImprEntity?contains(","+refTable.standardReferenceTableMappingName))?string("yes","no")=="no"> 
<#-- 导入外键引用的实体 -->
import com.rybbaby.tss.${baseInfo.modulesName}.${refTable.standardReferenceTableMappingName?uncapFirst}.entity.${refTable.standardReferenceTableMappingName};
<#assign tempImprEntity="${tempImprEntity},${refTable.standardReferenceTableMappingName}">
</#if>
</#list>

/**
 * @description ${baseInfo.businessDescription}
 * 
 * @author ${baseInfo.author}
 * 
 * @createDate ${baseInfo.nowDate}
 */
@Entity
@Table(name = "${table.tableName}")
@DynamicUpdate(true)
@DynamicInsert(true)
public class ${baseInfo.entityName} implements Serializable {
	
	private static final long serialVersionUID = ${table.serialVersionUID};
	
<#list table.columns as column>
	<#-- 基础属性 -->
	/** ${column.remarks} **/
	private ${column.columnJavaType} ${column.columnJavaFieldName};
</#list>
<#if table.foreignKeys?size gt 0>
	<#list table.foreignKeys as refTable>
	<#-- 外键引用属性 -->
	/** ${refTable.remarks} **/
	private ${refTable.standardReferenceTableMappingName} ${refTable.standardReferenceColumnNameMappingName};
	</#list>
	<#list table.foreignKeys as refTable>
	
	/**
	 * 方法: 取得${refTable.remarks}
	 *
	 * @return ${refTable.standardReferenceTableMappingName} ${refTable.remarks}
	 */
	@JoinColumn(name = "${refTable.referenceColumnName}" , insertable = false , updatable = false)
	@ManyToOne(fetch = FetchType.LAZY , targetEntity = ${refTable.standardReferenceTableMappingName}.class)
	public ${refTable.standardReferenceTableMappingName} get${refTable.standardReferenceColumnNameMappingName?capFirst}() {
		return this.${refTable.standardReferenceColumnNameMappingName};
	}
	
	/**
	 * 方法: 设置${refTable.remarks}
	 *
	 * @param ${refTable.standardReferenceColumnNameMappingName} ${refTable.remarks}
	 */
	public void set${refTable.standardReferenceColumnNameMappingName?capFirst}(${refTable.standardReferenceTableMappingName} ${refTable.standardReferenceColumnNameMappingName}) {
		this.${refTable.standardReferenceColumnNameMappingName} = ${refTable.standardReferenceColumnNameMappingName};
	}
	</#list>
</#if>
<#list table.columns as po>
	<#if !po.isPrimaryKey>
	
	/**
	 * 方法: 取得${po.remarks}
	 *
	 * @return ${po.columnJavaType} ${po.remarks}
	 */
	 <#if po.isVersionIdentifying?? && po.isVersionIdentifying?string("yes","no")=="yes" >
    @Version
	 </#if>
	@Column(name = "${po.columnName}", nullable= ${(po.isNullable???string(po.isNullable?string("true","false"),"")!"true")}<#if po.precision??&&po.precision gt 0>, precision = ${po.precision}</#if><#if po.scale?? && po.scale gt 0>, scale = ${po.scale}</#if><#if po.columnDisplaySize??>, length = ${po.columnDisplaySize?c}</#if>)
	public ${po.columnJavaType} get${po.columnJavaGetterOrSetterSuffix}() {
		return this.${po.columnJavaFieldName};
	}
	
	/**
	 * 方法: 设置${po.remarks}
	 *
	 * @param ${po.columnJavaFieldName} ${po.remarks}
	 */
	public void set${po.columnJavaGetterOrSetterSuffix}(${po.columnJavaType} ${po.columnJavaFieldName}) {
		<#if po.isForeignKey?string("yes","no")=="yes"&&(po.isNullable???string(po.isNullable?string("true","false"),"")!"true")=="true"&&po.columnJavaType=="java.lang.String">
		this.${po.columnJavaFieldName} = StringUtils.isBlank(${po.columnJavaFieldName}) ? null : ${po.columnJavaFieldName};
		<#else>
		this.${po.columnJavaFieldName} = ${po.columnJavaFieldName};
		</#if>
	}
	<#else>
	
	/**
	 * 方法: 取得${po.remarks}
	 *
	 * @return ${po.columnJavaType} ${po.remarks}
	 */
	<#if po.isAutoIncrement>
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	<#else>
	@Id
	@GeneratedValue(generator = "${table.tableName}IDGenerator" , strategy = GenerationType.AUTO)
	@GenericGenerator(name = "${table.tableName}IDGenerator" , strategy = "uuid")
	</#if>
	@Column(name = "${po.columnName}", nullable= ${(po.isNullable???string(po.isNullable?string("true","false"),"")!"true")}<#if po.precision??&&po.precision gt 0>, precision = ${po.precision}</#if><#if po.scale?? && po.scale gt 0>, scale = ${po.scale}</#if><#if po.columnDisplaySize??>, length = ${po.columnDisplaySize?c}</#if>)
	public ${po.columnJavaType} get${po.columnJavaGetterOrSetterSuffix}() {
		return this.${po.columnJavaFieldName};
	}
	
	/**
	 * 方法: 设置${po.remarks}
	 *
	 * @param ${po.columnJavaFieldName} ${po.remarks}
	 */
	public void set${po.columnJavaGetterOrSetterSuffix}(${po.columnJavaType} ${po.columnJavaFieldName}) {
		this.${po.columnJavaFieldName} = ${po.columnJavaFieldName};
	}
	</#if>
</#list>
}